{% comment %}
<!--
  Copyright (C) 2008 ZHENG Zhong <http://www.zhengzhong.net/>
  
  Created on 2009-05-11.
  $Id$
-->
{% endcomment %}

{#________________________________________________________________________________________________#}

<script type="text/javascript">//<![CDATA[

  function toggleBox(boxId) {
    $(boxId + " .view").toggle("slow");
    $(boxId + " .edit").toggle("slow");
  }
  
  //! Submits an AJAX form.
  function submitAjaxForm(boxId, formId) {
    // Select the AJAX form by ID.
    var form = $(formId);
    // Prepare AJAX options.
    var options = {
      type: form.attr("method"),
      url: form.attr("action"),
      data: form.serialize(),
      success: function(data) {
        // Replace the original AJAX box by the new one received from the server.
        $(boxId).after(data).remove();
      },
      error: function(xhr, status, exc) {
        // We are still in the original AJAX box: enable AJAX form and show AJAX error.
        $(":button", form).removeAttr("disabled");
        $(".ajax_indicator", form).hide();
        var ajax_error = $(boxId + " .ajax_error");
        ajax_error.text("Server failed to handle the AJAX request.");
        ajax_error.show();
      }
    };
    // Before submitting AJAX form, disable AJAX form and hide previous AJAX error.
    $(":button", form).attr("disabled", "disabled");
    $(".ajax_indicator", form).show();
    $(boxId + " .ajax_error").hide();
    // Submit the AJAX form, leave the rest to the AJAX callback functions.
    $.ajax(options);
    // Return false, to disable default submit event.
    return false;
  }

//]]></script>




